#pragma once

#include "InterfaceRealization.h"

#include "BehavioredClassifier.h"
#include "Interface.h"

namespace uml {

InterfaceRealization::InterfaceRealization(const QString& umlType)
    : Realization(umlType) {}

void InterfaceRealization::fromJson(const QJsonObject& json, QStringList& errorList) {
    if (json.isEmpty()) {
        return;
    }

    Realization::fromJson(json, errorList);
    contract_ = JsonSerializable::create<Interface>(json.value("contract"), errorList);

    implementingClassifier_ = JsonSerializable::create<BehavioredClassifier>(json.value("implementingClassifier"), errorList);

}

void InterfaceRealization::toJson(QJsonObject& json) {
    Realization::toJson(json);
    if (contract_) {
        QJsonObject contract_json;
        contract_->toJson(contract_json);
        json.insert("contract", contract_json);
    }
    if (implementingClassifier_) {
        QJsonObject implementingClassifier_json;
        implementingClassifier_->toJson(implementingClassifier_json);
        json.insert("implementingClassifier", implementingClassifier_json);
    }
}

/// <summary>
/// contract getter
/// References the Interface specifying the conformance contract.
/// </summary>
shared_ptr<Interface> InterfaceRealization::contract() const {
    return contract_;
}

/// <summary>
/// contract setter
/// References the Interface specifying the conformance contract.
/// </summary>
void InterfaceRealization::setContract(shared_ptr<Interface> value) {
    contract_ = value;
}

/// <summary>
/// implementingClassifier getter
/// References the BehavioredClassifier that owns this InterfaceRealization, i.e.,
/// the BehavioredClassifier that realizes the Interface to which it refers.
/// </summary>
shared_ptr<BehavioredClassifier> InterfaceRealization::implementingClassifier() const {
    return implementingClassifier_;
}

/// <summary>
/// implementingClassifier setter
/// References the BehavioredClassifier that owns this InterfaceRealization, i.e.,
/// the BehavioredClassifier that realizes the Interface to which it refers.
/// </summary>
void InterfaceRealization::setImplementingClassifier(shared_ptr<BehavioredClassifier> value) {
    implementingClassifier_ = value;
}

} // namespace uml
